﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定义全局变量</title>
    <script type="text/javascript">
        function toGlobal(varName){
            window.execScript(varName); //定义varName为全局使用
        }
        toGlobal('window.varText="全局变量";'); //设置全局变量的值
        alert(barText);                         // 显示全局变量的值
    </script>
</head>
<body>

</body>
</html>